﻿using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.DTO;
using DXApplicationTangche.UC.订单一览新.订单预览新.service;
using mendian;
using System;
using System.Collections.Generic;

namespace DXApplicationTangche.UC.流程.Service
{
    public class 流程Service
    {
        /// <summary>
        /// 取barcode最新状态
        /// </summary>
        /// <param name="barcode"></param>
        /// <returns></returns>
        public static ProcessInstanceRecordDTO getBarcodeStatus(String barcode)
        {
            return
                FunctionHelper.JsonDeserialization<ProcessInstanceRecordDTO>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/process/getBarcodeStatus?barcode=" + barcode
                        + "&processTemplateId=" + ProcessTemplateIdConsts.REWORK_PROCESS_TEMPLATE_ID
                        )
                    );
        }
        /// <summary>
        /// 根据流程模板Id和成衣码查询当前流程节点实例，并跳转下一节点
        /// </summary>
        /// <param name="processTemplateId"></param>
        /// <param name="barcode"></param>
        /// <param name="assignee"></param>
        /// <param name="remark"></param>
        /// <returns></returns>
        public static String getCurrentNodeIdByTemplateIdAndBarcode(String processTemplateId, String barcode, String assignee, String remark)
        {
            return
                RestCall.httpGetMethod(
                        URL.接口url + "/process/getCurrentNodeIdByTemplateIdAndBarcode?processTemplateId=" + processTemplateId + "&barcode=" + barcode + "&assignee=" + assignee + "&remark=" + remark
                    );
        }
        /// <summary>
        /// 判断是否客订订单（定制和客套）
        /// </summary>
        /// <param name="barcode"></param>
        /// <returns></returns>
        public static Boolean isCustomerMade(String barcode)
        {
            return
                FunctionHelper.JsonDeserialization<Boolean>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/barcode/isCustomerMade?barcode=" + barcode
                    ));
        }
    }
    public class ProcessTemplateIdConsts
    {
        public const String IN_STOCK_PROCESS_TEMPLATE_ID = "0f932b8a8d974bf0ad93a6c0cc59f8f3";    //  入库流程
        public const String REWORK_PROCESS_TEMPLATE_ID = "ef5d8014ffea4b26bc2d233d94f143d3";    //  返修流程
    }

    /// <summary>
    /// 流程状态
    /// </summary>
    public class ProcessStatusConsts
    {
        public const String ON_GOING = "进行中";
        public const String DONE = "完成";
    }
    public class ProcessInstanceRecordDTO
    {
        public String id { get; set; }   //  流程定义——销售退货
        public String processTemplateId { get; set; }    //  流程定义id
        public String barcode { get; set; }
        public DateTime startTime { get; set; } //  发起时间
        public String assigner { get; set; }  //  发起人
        public String status { get; set; }  //  状态——进行中，完成（完成有自动完成和手动完成）
        public DateTime completionTime { get; set; }     //  完成时间
        public String currentNodeId { get; set; }  //  当前节点id

        public String barcodeStatus { get; set; }   //  barcode状态码，如返修类型等
        public String customerName { get; set; }    //  客户姓名
        public String consignee { get; set; }   //  收件人
        public String mobile { get; set; }
        public String addressProvince { get; set; }//省
        public String addressCity { get; set; }//市
        public String addressDistrict { get; set; }//区
        public String addressDetail { get; set; }//详细地址

        public String orderStatus { get; set; }//  订单状态    @See top.toptimus.constValue.PMCOrderStatusConsts
        public OrderCommitDTO返回 orderCommitDto { get; set; } = new OrderCommitDTO返回();
        public Boolean deprecated { get; set; } //  是否作废

        public ProcessInstanceRecordDTO()
        {

        }
    }

}
